package org.opens.guava.utilites.eventBus.dao;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import org.opens.guava.utilites.eventBus.base.Request;
import org.opens.guava.utilites.eventBus.base.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RequestSave {

    private final static Logger LOGGER = LoggerFactory.getLogger(RequestSave.class);

    private EventBus eventBus;

    public RequestSave() {
    }

    public RequestSave(EventBus eventBus) {
        this.eventBus = eventBus;
        eventBus.register(this);
    }

    @Subscribe
    public void save(Request request) {
        LOGGER.info("{} 成功保存了 {}", this.getClass().getSimpleName(), request.toString());
        Response response = new Response(200, "success");
        eventBus.post(response);
    }

}
